﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace EasyAnimation {
    [AddComponentMenu("EasyAnimation/非UI对象/颜色渐变")]
    public class EasyAnimation_Fade_Renderer : EasyAnimationTemplateMethod
    {
        [Header("起始颜色")]
        public Color startColor;
        [Header("结束颜色")]
        public Color endColor;
        [Header("Renderer对象(默认获取第一个)")]
        public Renderer image;

        private bool isImage = false;

        protected override void Easy_Animation_Awake()
        {

            image = GetComponent<Renderer>();
            if (image != null)
            {
                image.material.color = startColor;
                isImage = true;
            }

        }

        protected override void PrimitiveOperation_Start()
        {
            ead = new EaseAinmationDrive(1, 0, 1, easetype);
        }

        protected override bool PrimitiveOperation_UpDate(float time)
        {
            if (isImage)
            {
                float i = ead.getProgress(time);
                image.material.color = Color.Lerp(startColor, endColor, i);
                //float s = startAlpha + (endAlpha - startAlpha) * i;
                //image.color = new Color(image.color.r, image.color.g, image.color.b, s);

                return true;
            }
            else
            {
                return false;
            }
        }

        public override void Rese()
        {
            if (isImage)
            {
                image.material.color = startColor;
            }
        }
    }
}
